package com.gangan.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gangan.model.CmsWish;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gangan.model.view.CmsWishContentView;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2019-08-20
 */
public interface CmsWishMapper extends BaseMapper<CmsWish> {
    @Select("SELECT\n" +
            "\twish.id,\n" +
            "\twish.cms_id,\n" +
            "\twish.addtime,\n" +
            "\twish.`status`,\n" +
            "\twish.wish_type,\n" +
            "\t(\n" +
            "        CASE wish.wish_type\n" +
            "        WHEN 0 THEN\n" +
            "            content.title \n" +
            "        WHEN 1 THEN\n" +
            "            activity.label\n" +
            "        END\n" +
            "    ) titlename,\n" +
            "\t\t\t(\n" +
            "        CASE wish.wish_type\n" +
            "        WHEN 0 THEN\n" +
            "            content.image \n" +
            "        WHEN 1 THEN\n" +
            "            activity.img_orogin\n" +
            "        END\n" +
            "    ) imageurl\n" +
            "\t\n" +
            "FROM\n" +
            "\ttl_cms_wish wish\n" +
            "\tLEFT JOIN tl_cms_content content ON wish.cms_id = content.id \n" +
            "\tAND wish.wish_type = 0 \n" +
            "\tleft JOIN tl_activity activity on wish.cms_id = activity.id\n" +
            "\tAND wish.wish_type = 1\n" +
            "WHERE\n" +
            "\twish.user_id = #{userId} \n" +
            "ORDER BY\n" +
            "\twish.addtime DESC")
    List<CmsWishContentView> selectUserListPage(Page<CmsWishContentView> pagination,@Param("userId") Integer userId);


}
